﻿using System;

namespace AgFractal.Fractals
{
    public class BarnsleyJulia : AbstractFractal
    {
        public BarnsleyJulia()
        {
            ID = new Guid("F3CA7041-31FE-4e65-A3C0-AECFC394FC9F");
            Name = Description = "Barnsley julia";
            R1 = -3; I1 = 2; R2 = 3; I2 = -2;
            
            var cParam = new FractalParameter { Name = "c", ComplexValue = c };
            cParam.PropertyChanged += (s, e) => c = cParam.ComplexValue;
            parameter.Add(cParam);
        }

        private Complex c = new Complex(0.6, 1.1);
        protected override short Calculate(double r, double i, short MaxIteration)
        {
            short j;
            Complex z = new Complex(r, i);
            
            for (j = 0; j < MaxIteration; j++)
            {
                if (z.r >= 0)
                    z.r = z.r - 1;
                else
                    z.r = z.r + 1;
                
                z = z * c;
                if (z.Abs2() > 4) break;
            }
            return j;
        }
    }
}